package com.cold.manage.controller;

import com.cold.common.core.domain.AjaxResult;
import com.cold.common.domain.AlertMessage;
import com.cold.manage.service.IDruidService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/manage/druid")
public class DruidMessageController {

    @Resource
    private IDruidService druidService;

    @RequestMapping("messages")
    public AjaxResult getTemHumMessage(String hostName,@RequestParam(required = false,defaultValue = "20") Integer limit){
        Map<String,Object> params = new HashMap<>();
        params.put("hostName",hostName);
        params.put("limit",limit);
        Map<String, Object> map = druidService.selectChartTemHum(params);
        return AjaxResult.success(map);
    }

    @RequestMapping("latest-messages")
    public AjaxResult getLatestMessage(){
        List<AlertMessage> messages = druidService.selectLatestMessages();
        return AjaxResult.success(messages);
    }
}
